even_numbers = [x for x in range(2, 101, 2)]
print(even_numbers)
# [2, 4, 6, ..., 100]


squared = [x**2 for x in even_numbers]
print(squared)
# [4, 16, 36, ..., 10000]


filtered = [x for x in squared if x <= 1000]
print(filtered)
# 移除10000, 9604, ...等


reversed_list = filtered[::-1]
print(reversed_list)
# 如[900, 784, 676, ..., 4]


first_10 = reversed_list[:10]
print(first_10)


first_10.extend([101, 102, 103])
print(first_10)


average = sum(first_10) / len(first_10)
print(average)

max_val = max(first_10)
print(max_val)
min_val = min(first_10)
print(min_val)


try:
    index = first_10.index(11)
except ValueError:
    index = -1  # 不存在时返回-1
print(index)



# 方法1: for循环
for i in range(len(first_10)):
    first_10[i] = str(first_10[i])
print(first_10)
# 方法2: while循环
i = 0
while i < len(first_10):
    first_10[i] = str(first_10[i])
    i += 1
print(first_10)


float_list = [float(x) for x in first_10]
print(float_list)


count = len([x for x in float_list if x > 50])
print(count)


float_list.insert(2, 99)  # 索引2是第3个位置
print(float_list)


float_list.pop()
print(float_list)


doubled = [x*2 for x in float_list]
print(doubled)


lower = [x for x in doubled if x <= 50]
print(lower)
higher = [x for x in doubled if x > 50]
print(higher)


element_dict = {val: idx for idx, val in enumerate(doubled)}
print(element_dict)


for index, value in enumerate(doubled):
    print(f"Index {index}: {value}")


import random
random_element = random.choice(doubled)
print(random_element)


with open('output.txt', 'w') as f:
    for num in doubled:
        f.write(f"{num}\n")